clear
set more off
set type double
graph drop _all
program drop _all
set scheme s2mono
import excel "\\file\UsersW$\wrr15\Home\My Documents\My Files\ANDY KIM\REVISION FOR WORLD DEVELOPMENT\DATA AND CODE\MA Data (13 July 2016).xlsx", firstrow case(lower)
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\ANDY KIM\REVISION FOR WORLD DEVELOPMENT\DATA AND CODE\Appendix.smcl", replace

// RECODING VARIABLES
// The first thing we do is generate some new variables
// because some of our old study characteristics had too few
// observations
gen endog = (tsls == 1 | gmm == 1)
gen se_notols = (se_het == 1 | se_other == 1)
gen fdigdp = fditype0

// This section transforms the continuous variables so they are 
// deviations from the mean.  This makes the constant more "interpretable".
gen pubyear2 = pubyear
egen pubyearm = mean(pubyear2)
replace pubyear = pubyear2 - pubyearm

gen datayear2 = datayear
egen datayearm = mean(datayear2)
replace datayear = datayear2 - datayearm

gen span2 = span
egen spanm = mean(span2)
replace span = span2 - spanm

gen journalrank2 = journalrank
egen jrmean = mean(journalrank2)
replace journalrank = journalrank2 - jrmean


//CONVERTING TSTATS TO PARTICAL CORRELATION COEFFICIENTS, r
gen eff = sqrt(tstat^2/(tstat^2+df))
gen r = eff if positive == 1
replace r = -1*eff if r == .
gen varR = (1-r^2)/df
gen seR = sqrt(varR)
gen pcc = r

metareg r pubyear datayear span subset fdigdp initial endog ///
se_notols dvtype1 dvtype2 dvtype_other panel_nofe panel_fe ts ///
cjournal notjournal journalrank, wsse(seR)
scalar tau2 = e(tau2)
display tau2
gen revarR= varR + tau2
gen reseR = sqrt(revarR)

gen pubyearr = pubyear/reseR 
gen datayearr = datayear/reseR 
gen spann = span/reseR 
gen subsett = subset/reseR 
gen fdigdpp = fdigdp/reseR
gen initiall = initial/reseR
gen endogg = endog/reseR
gen se_notolss = se_notols/reseR
gen dvtype11 = dvtype1/reseR 
gen dvtype22 = dvtype2/reseR 
gen dvtype_otherr = dvtype_other/reseR 
gen panel_nofee = panel_nofe/reseR 
gen panel_fee = panel_fe/ reseR 
gen tss = ts/reseR   
gen cjournall = cjournal/reseR 
gen notjournall = notjournal/reseR 
gen journalrankk = journalrank/reseR
gen conss = 1/reseR
gen ser = 1
gen retstatR = r/reseR 



*--------------------------------------------------------------------------------*
*   APPENDIX: Random Effects Multiple Meta-Regression                             *
*--------------------------------------------------------------------------------*

// RANDOM EFFECTS - Full Specification

// These specifications include the SeR term
// NOTE: The constant term is the SER term


//This first regression gives equal weight to each observation
// Table APPENDIX 1 - Column 1
reg retstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss,  vce(cluster id)
display e(r2_a)

//This regression gives equal weight to each study
// Table APPENDIX 1 - Column 3
reg retstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss [pweight = weight], vce(cluster id)
display e(r2_a)

// NOTE: These specification omit the SeR term

//This first regression gives equal weight to each observation
// Table APPENDIX 1 - Column 2
reg retstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss, noc vce(cluster id)
display e(r2_a)

//This regression gives equal weight to each study
// Table APPENDIX 1 - Column 4
reg retstatR pubyearr datayearr spann subsett fdigdpp initiall endogg ///
se_notolss dvtype11 dvtype22 dvtype_otherr panel_nofee panel_fee tss ///
cjournall notjournall journalrankk conss [pweight = weight], noc vce(cluster id)
display e(r2_a)

/*

// RANDOM EFFECTS - Stepwise Specification where SeR term can be kept or dropped

//This first regression gives equal weight to each observation
stepwise, pr(0.05) lockterm1:reg retstatR conss pubyearr datayearr spann ///
subsett fdigdpp initiall endogg se_notolss dvtype11 dvtype22 dvtype_otherr ///
panel_nofee panel_fee tss cjournall notjournall ser, noc cluster(id)
display e(r2_a)

//This first regression gives equal weight to each observation
stepwise, pr(0.05) lockterm1:reg retstatR conss pubyearr datayearr spann ///
subsett fdigdpp initiall endogg se_notolss dvtype11 dvtype22 dvtype_otherr ///
panel_nofee panel_fee tss cjournall notjournall ser [pweight = weight], noc cluster(id)
display e(r2_a)

*/

log close

